lionsApp
    .controller('offline-priceCtrl', ['$scope', 'lionsHttp', 'myFunction', '$state', function ($scope, lionsHttp, myFunction, $state) {
        $scope.code = myFunction.getUrlParam(location.href).code
        lionsHttp.detail({}, {code: $scope.code}, function (data) {
            $scope.detailInfo = data.data.goods
        })
        lionsHttp.areaList({}, {}, function (data) {
            $scope.areaList = data.data
        })
        $scope.areaChange = function () {
            $scope.userName = ''
            if($scope.userArea == 999){
                $scope.noName = true
                $scope.areaName = '爱心人士'
                $scope.teamName = '爱心人士'
            }else{
                $scope.noName = false
                $scope.areaList.forEach( function (item) {
                    if(item.area == $scope.userArea){
                        $scope.areaName = item.areaName
                    }
                })
            }
            lionsHttp.teamList({}, {area: $scope.userArea}, function (data) {
                $scope.teamList = data.data
            })
        }
        $scope.teamChange = function () {
            $scope.teamList && $scope.teamList.forEach( function (item) {
                if(item.id == $scope.userTeam){
                    $scope.teamName = item.name
                }
            })
            lionsHttp.userList({}, {team: $scope.userTeam}, function (data) {
                $scope.userList = data.data
            })
        }
        $scope.userChange = function () {
            $scope.userList && $scope.userList.forEach( function (item) {
                if(item.id == $scope.userId){
                    $scope.userName = item.name
                    $scope.error = false
                }
            })
        }
        $scope.next = function () {
            if(!$scope.userName){
                $scope.error = '请填写拍品人姓名'
                return
            }
            if(!$scope.auctionPrice){
                $scope.error = '请填写竞拍价格'
                return
            }
            $scope.goConfirm = true
            $scope.confirmError = '请仔细核对拍品人信息'
        }
        $scope.reSelect = function () {
            $scope.goConfirm = false
        }
        $scope.typeIn =function () {
            $scope.error = '录入中，请等待...'
            if(!$scope.btnDisabled){
                $scope.btnDisabled = true
                lionsHttp.offlinePrice({}, {
                    userName: $scope.userName,
                    userId: $scope.userId,
                    teamId: $scope.userTeam,
                    goodsCode: $scope.detailInfo.code,
                    amount: $scope.auctionPrice
                }, function (data) {
                    $scope.btnDisabled = false
                    if(data.statusCode == 0){
                        $scope.error = '录入成功'
                        $state.go('offlineList', {reload: true})
                    }else{
                        $scope.error = data.statusMessage
                    }
                })
            }
        }
    }])